package dev.ece.core.clearup;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * GL垃圾回收管理
 * @author 飘渺青衣
 * <b>E-mail：</b>3375758@qq.com
 */
public class ClearUpGLRubbishManager {

	private final static Queue<ClearUpGLRubbish> RUBBISH_QUEUE = new LinkedBlockingQueue<ClearUpGLRubbish>();
	
	/**
	 * 将垃圾推入清理队列
	 * @param rubbish
	 */
	public static void push(ClearUpGLRubbish rubbish) {
		if(!RUBBISH_QUEUE.contains(rubbish)) {
			RUBBISH_QUEUE.add(rubbish);
		}
	}
	
	/**
	 * 开始清理，图形引擎会在每帧最后执行此操作
	 */
	public static void clearup() {
		ClearUpGLRubbish rubbish = null;
		while((rubbish = RUBBISH_QUEUE.poll()) != null) {
			rubbish.clearup();
		}
	}
}
